﻿using System;
using Fly.Data;
using FlyWebFrame.Model;

namespace FlyWebFrame.Action.admin
{
    public class login : Fly.Web.Action.Handler
    {
        public string username = "";
        public string login_script = "";

        public void Handle()
        {
            if (Admin.Logged())
            {
                Redirect("/admin");
            }

            SetView("/html/admin/login.htm");
            username = Form["username"];
            if (Form["submited"] == "true")
            {
                Admin admin = new Admin();
                if (Form["username"] != "" && Form["password"] != "")
                {
                    admin.Name = Form["username"];
                    admin.Pass = Form["password"];
                    Result result = admin.Login();
                    if (result.Status)
                    {
                        Refresh();
                    }
                    else
                    {
                        login_script += "$('#login_error').html('" + result.Message + "');";
                    }
                }
                else
                {
                    login_script += "$('#login_error').html('Bạn chưa nhập đủ thông tin!');";
                }
            }

        }
    }
}